/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cashmate.struts;

import com.cashmate.hibernate.dao.AreaDAO;
import com.cashmate.hibernate.pojo.Areas;
import com.cashmate.hibernate.pojo.Borrowers;
import com.cashmate.hibernate.pojo.Employees;
import com.opensymphony.xwork2.ActionSupport;
import java.io.InputStream;
import java.io.StringBufferInputStream;
import java.util.List;
import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;

/**
 *
 * @author Sarah
 */

    @Action(value="/get-names",results={
        @Result(name="success", type="stream",params={"inputName","inputStream","contentType","text/html"}),
        @Result(name="error", location="WEB-INF/error/indexError.html")
    })
public class GetNames extends ActionSupport {

    private static Logger logger = Logger.getLogger(GetNames.class);
    private AreaDAO ar = (AreaDAO) ServletActionContext.getServletContext().getAttribute("areaDAO");
   
    public String acodecoll, acode;
    private InputStream inputStream;
    private List<Borrowers> borrowers;
    private List<String> borlist;
    private Employees emp;
    private Areas area;
    

    public void setAcode(String acodecoll) {
        this.acodecoll = acodecoll;
    }

    public void setAcodeColl(String acode) {
        this.acode = acode;
    }

    public InputStream getInputStream() {
        return inputStream;
    }

    public List<String> getBorlist() {
       return borlist;
    }

    public Employees getEmp(){
        return emp;
    }

    public Areas getArea(){
        return area;
    }



    @Override
    public String execute() {
        try {
            emp= ar.getAreasMap().get(acodecoll).getEmployees();
            String id = emp.getIdnumber();
            String name = emp.getCompletename();
            area = ar.getAreasMap().get(acodecoll);

            
            inputStream = new StringBufferInputStream(id + "|" + name+"|");

            return SUCCESS;

        } catch (Exception e) {
            System.out.println("getname:"+e.toString());
        }
        return SUCCESS;
    }
}
